package com.chuhe.starry.controller;

import com.chuhe.common.domain.entity.GroupInfo;
import com.chuhe.common.domain.query.PaginationResultVO;
import com.chuhe.common.domain.vo.req.AdminLoadGroupReq;
import com.chuhe.common.domain.vo.resp.ApiResult;
import com.chuhe.common.exception.BusinessException;
import com.chuhe.common.exception.CommonErrorEnum;
import com.chuhe.starry.dao.GroupInfoDao;
import com.chuhe.starry.service.GroupInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;

/**
 * @Author: 楚河
 * @Date: 2025年05月18日14:09
 */
@RestController()
@RequestMapping("/admin")
@Api(value = "群组管理接口", tags = "群组管理相关API", description = "群组管理API")
public class AdminGroupController {
    @Autowired
    private GroupInfoService groupInfoService;
    @Autowired
    private GroupInfoDao groupInfoDao;

    @RequestMapping("/loadGroup")
    @ApiOperation("查询所有群组")
    public ApiResult<PaginationResultVO<GroupInfo>> loadGroup(AdminLoadGroupReq req){
        return ApiResult.success(groupInfoService.findListByPage(req));
    }

    @RequestMapping("/dissolutionGroup")
    @ApiOperation("解散群组")
    public ApiResult<?> dissolutionGroup(@NotEmpty String groupId){
        GroupInfo groupInfo = groupInfoDao.getGroupByGroupid(groupId);
        if (null == groupInfo) {
            throw new BusinessException(CommonErrorEnum.CODE_200);
        }
        groupInfoService.dissolutionGroup(groupInfo.getGroupOwnerId(), groupId);
        return ApiResult.success(null);
    }


}
